package com.cn.jinl.controller;

import com.cn.jinl.api.IOrderBackInfoService;
import com.cn.jinl.domain.OrderBackInfo;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/orderBack")
public class OrderBackInfoController {

    @Autowired
    private IOrderBackInfoService orderBackInfoService;

    @RequestMapping("/getOrderBackInfoList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<OrderBackInfo>> getOrderBackInfoList(@PathVariable(value = "frontToken",required = true) String frontToken, @RequestBody QueryForm queryForm) throws Exception{
        JsonResponse<List<OrderBackInfo>> response = new JsonResponse<>();
        List<OrderBackInfo> orders = orderBackInfoService.getOrderBackInfoList(queryForm);
        response.setResult(orders);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/getOrderBackInfoByOrderId/{frontToken}")
    @ResponseBody
    public JsonResponse<OrderBackInfo> getOrderBackInfoByOrderId(@PathVariable(value = "frontToken",required = true) String frontToken, String orderId) throws Exception{
        JsonResponse<OrderBackInfo> response = new JsonResponse<>();
        OrderBackInfo order = orderBackInfoService.getOrderBackInfoByOrderId(orderId);
        response.setResult(order);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/disOrderBackInfo/{frontToken}")
    @ResponseBody
    public JsonResponse<String> disOrderBackInfo(OrderBackInfo orderBackInfo, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = orderBackInfoService.disOrderBackInfo(orderBackInfo);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/updateOrderBackInfo/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateOrderBackInfo(OrderBackInfo orderBackInfo, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = orderBackInfoService.updateOrderBackInfo(orderBackInfo);
        return CommonUtil.getResponseData(response,result);
    }

    //应退确认
    @RequestMapping("/updateOrderBackSure/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateOrderBackSure(OrderBackInfo orderBackInfo, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = orderBackInfoService.updateOrderBackSure(orderBackInfo);
        return CommonUtil.getResponseData(response,result);
    }

    //确认完成
    @RequestMapping("/updateOrderBackComplete/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateOrderBackComplete(OrderBackInfo orderBackInfo, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = orderBackInfoService.updateOrderBackComplete(orderBackInfo);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/addOrderBackInfo/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addOrderBackInfo(OrderBackInfo orderBackInfo, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = orderBackInfoService.addOrderBackInfo(orderBackInfo);
        return CommonUtil.getResponseData(response,result);
    }


    //获取报数列表
    @RequestMapping("/api/getOrderBackInfoList")
    @ResponseBody
    public JsonResponse<List<OrderBackInfo>> getAPIOrderBackInfoList(QueryForm queryForm) throws Exception{
        JsonResponse<List<OrderBackInfo>> response = new JsonResponse<>();
        List<OrderBackInfo> orders = orderBackInfoService.getAPIOrderBackInfoList(queryForm);
        response.setResult(orders);
        response.setSuccess(true);
        return response;
    }

    //更新报数
    @RequestMapping("/api/updateBaoshuOrderBackInfo")
    @ResponseBody
    public JsonResponse<String> updateBaoshuOrderBackInfo(OrderBackInfo orderBackInfo) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = orderBackInfoService.updateBaoshuOrderBackInfo(orderBackInfo);
        return CommonUtil.getResponseData(response,result);
    }


    //获取退货待入库列表
    @RequestMapping("/api/getOrderBackStorageList")
    @ResponseBody
    public JsonResponse<List<OrderBackInfo>> getOrderBackStorageList(QueryForm queryForm) throws Exception{
        JsonResponse<List<OrderBackInfo>> response = new JsonResponse<>();
        List<OrderBackInfo> orders = orderBackInfoService.getOrderBackStorageList(queryForm);
        response.setResult(orders);
        response.setSuccess(true);
        return response;
    }

    //测试更新报数
    @RequestMapping("/api/updateTestBaoshuOrderBackInfo")
    @ResponseBody
    public JsonResponse<String> updateTestBaoshuOrderBackInfo() throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        OrderBackInfo orderBackInfo = new OrderBackInfo();
        orderBackInfo.setId("5deb7ec6orderback-cd4borderback-4c9aorderback-95edorderback-e5d45a11ecc9");
        orderBackInfo.setBaoshuUser("admin");
        orderBackInfo.setDriver("圆通");
        orderBackInfo.setRemark("丢了一件");
        orderBackInfo.setWuliuCount("5");
        String result = orderBackInfoService.updateBaoshuOrderBackInfo(orderBackInfo);
        return CommonUtil.getResponseData(response,result);
    }

    //数据分析
    @RequestMapping("/getDataAnalysisList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<Map<Object, Object>>> getDataAnalysisList( @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<Map<Object, Object>>> response = new JsonResponse<List<Map<Object, Object>>>();
        List<Map<Object, Object>> list  = orderBackInfoService.getDataAnalysisList();
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }
}
